package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcWatchDataLocationMapper;
import com.csun.cmny.provider.model.domain.DmcWatchDataLocation;
import com.csun.cmny.provider.model.dto.watch.WatchLocationQueryDto;
import com.csun.cmny.provider.model.vo.watch.WatchLocationVo;
import com.csun.cmny.provider.service.DmcWatchDataLocationService;
import com.csun.cmny.provider.service.DmcWatchDataService;
import com.csun.cmny.util.PublicUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-24 15:10
 * @Description: the class dmc watch data location service impl
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DmcWatchDataLocationServiceImpl extends BaseService<DmcWatchDataLocation>
        implements DmcWatchDataLocationService {

    @Resource
    private DmcWatchDataService dmcWatchDataService;

    @Resource
    private DmcWatchDataLocationMapper dmcWatchDataLocationMapper;


    /**
     * query real location by device id
     *
     * @param deviceId device id
     * @return watch real location vo
     */
    @Override
    public WatchLocationVo queryRealLocationByDeviceId(Long deviceId) {

        return dmcWatchDataLocationMapper.queryRealLocationByDeviceId(deviceId);
    }

    /**
     * query hist location list with page
     *
     * @param watchLocationQueryDto watch location query dto
     * @return the page info.
     */
    @Override
    public PageInfo queryHistLocationListWithPage(WatchLocationQueryDto watchLocationQueryDto) {

        PageHelper.startPage(watchLocationQueryDto.getPageNum(), watchLocationQueryDto.getPageSize());

        List<WatchLocationVo> watchLocationVoList = dmcWatchDataLocationMapper
                .queryHistLocationListWithPage(watchLocationQueryDto);

        return new PageInfo<>(watchLocationVoList);
    }

    /**
     * 删除位置数据
     *
     * @param deviceId the device id
     *
     * @return the int
     */
    @Override
    public Integer removeDmcWatchDataLocation(Long deviceId) {

        DmcWatchDataLocation dmcWatchDataLocation = new DmcWatchDataLocation();
        dmcWatchDataLocation.setDeviceId(deviceId);

        return dmcWatchDataLocationMapper.delete(dmcWatchDataLocation);
    }
}
